#include "pagrid.h"
/*-------------------------------------------------------------------------*/
/**
  @file		util.c
  @author	Renaud Wanchoor
  @date	July 2004
  @version	$Revision: 2.6 $
  @brief	utilities
  @update date	March 2007 by Xiaochen Wu

  only two functions, one that read both graph and grid, and one for timing 
  
*/
/*--------------------------------------------------------------------------*/

/**
 * \brief read both graph and grid files
 *
 * dynamically allocate *graph and *grid and store data of F_graph and F_grid
 * in those two structures, *graph and *grid need to be freed using
 * LIBG_Free(*graph) and LIBN_Free(*grid);
 * \param graph pointer to pointer of graph structure
 * \param F_graph string that points to the file in which the graph is described
 * \param grid pointer to pointer of grid structure
 * \param F_grid string that points to the file in which the grid is described
 */
void readfiles( GraphType** graph,char* F_graph,
		GridType** grid,char* F_grid, int NBytes){
  FILE* fp;
  
  /* read graph */
  fp = fopen(F_graph,"r");
  *graph = LIBG_Read(fp);
  fclose(fp);

  /* read grid */
  fp = fopen(F_grid,"r");
  *grid = LIBN_Read(fp, NBytes);
  fclose(fp);

  /* generate processor proportion */
  LIBN_Progen(*graph,*grid);
}

/**
 * \brief timing of the program in seconds
 *
 * \param return the processor time used by the program in second
 */
double gettimes() {return (double)clock()/(double)CLOCKS_PER_SEC;}
